package com.lujieni.springbootmapconstructor.web;

import com.lujieni.springbootmapconstructor.dto.HobbyDO;
import com.lujieni.springbootmapconstructor.dto.HobbyDTO;
import com.lujieni.springbootmapconstructor.dto.UserDO;
import com.lujieni.springbootmapconstructor.dto.UserDTO;
import com.lujieni.springbootmapconstructor.mapper.UserConvert;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @Author：Jie Ni
 * @Date: 2025/7/8 17:46
 * @Description:
 */
@RestController
@RequiredArgsConstructor
public class HelloController {

    @GetMapping(value = "/convertDO")
    public UserDTO convertDO() {
        HobbyDO hobbyDO = new HobbyDO();
        hobbyDO.setName("睡觉");
        hobbyDO.setRemark("穷人的快乐就是睡觉");

        UserDO user = new UserDO();
        user.setId(1L);
        user.setUsername("lujieni");
        user.setEmail("982584989@qq.com");
        user.setCreateTime(LocalDateTime.now());
        user.setBirthday(LocalDateTime.now());
        user.setHobby(hobbyDO);

        UserDTO dto = UserConvert.INSTANCE.toDto(user);
        return dto;
    }

    @GetMapping(value = "/convertDTO")
    public UserDO convertDTO() {
        UserDTO user = new UserDTO();
        user.setId(1L);
        user.setName("lujieni");
        user.setEmail("982584989@qq.com");
        user.setFormattedDate("2025-07-08 17:46:00");
        UserDO entity = UserConvert.INSTANCE.toEntity(user);
        return entity;
    }

    @GetMapping(value = "/convertDOList")
    public List<UserDTO> convertDTOList() {
        UserDO user = new UserDO();
        user.setId(1L);
        user.setUsername("lujieni");
        user.setEmail("982584989@qq.com");
        user.setCreateTime(LocalDateTime.now());

        UserDO user2 = new UserDO();
        user2.setId(2L);
        user2.setUsername("qizi");
        user2.setEmail("1474417145@qq.com");
        user2.setCreateTime(LocalDateTime.now());


        List<UserDTO> result = UserConvert.INSTANCE.toDtoList(Arrays.asList(user, user2));
        return result;
    }

}
